package com.ck.ips.core.listener;

import com.ck.ips.core.listener.event.LoginSuccessEvent;
import com.ck.ips.service.LoginService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.context.event.EventListener;
import org.springframework.scheduling.annotation.Async;
import org.springframework.stereotype.Component;

/**
* @Description: 登录成功监听
* @Author: hf
* @Date:    2019/5/5 16:49
* @Version: 1.0
*/
@Component
public class LoginSuccessListener{

    @Autowired
    private LoginService loginService;


    @Async
    @EventListener
    public void loginSuccess(LoginSuccessEvent loginSuccessEvent){

        // 保存此次登录记录
        loginService.saveLoginSuccessRecord(loginSuccessEvent);

        // 移除登录失败记录缓存
        loginService.removeLoginFailCache(loginSuccessEvent.getUserName());

    }
}
